<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="FutureTask和FutureFutureFuture接口主要方法：12345678910boolean cancel(boolean mayInterruptIfRunning);boolean isCancelled();boolean isDone();V get() throws InterruptedException, ExecutionException;V get(long t">
<meta name="keywords" content="java">
<meta property="og:type" content="article">
<meta property="og:title" content="java多线程之FutureTask">
<meta property="og:url" content="http://www.wuxiantao123.cn/2019/07/01/java多线程之FutureTask-Future和Callable/index.html">
<meta property="og:site_name" content="费曼的门徒">
<meta property="og:description" content="FutureTask和FutureFutureFuture接口主要方法：12345678910boolean cancel(boolean mayInterruptIfRunning);boolean isCancelled();boolean isDone();V get() throws InterruptedException, ExecutionException;V get(long t">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.wuxiantao123.cn/source/images/jus/FutureTask1.png">
<meta property="og:updated_time" content="2019-07-01T14:51:51.296Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java多线程之FutureTask">
<meta name="twitter:description" content="FutureTask和FutureFutureFuture接口主要方法：12345678910boolean cancel(boolean mayInterruptIfRunning);boolean isCancelled();boolean isDone();V get() throws InterruptedException, ExecutionException;V get(long t">
<meta name="twitter:image" content="http://www.wuxiantao123.cn/source/images/jus/FutureTask1.png">





  
  
  <link rel="canonical" href="http://www.wuxiantao123.cn/2019/07/01/java多线程之FutureTask-Future和Callable/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>java多线程之FutureTask | 费曼的门徒</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">费曼的门徒</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">Feynman follower</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-备忘录">

    
    
    
      
    

    

    <a href="/books" rel="section"><i class="menu-item-icon fa fa-fw fa-book"></i> <br>备忘录</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-计划待办">

    
    
    
      
    

    

    <a href="/todolist" rel="section"><i class="menu-item-icon fa fa-fw fa-calendar"></i> <br>计划待办</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    
  
  

  

  <a href="https://github.com/peach-boy" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.wuxiantao123.cn/2019/07/01/java多线程之FutureTask-Future和Callable/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Thomas Wu">
      <meta itemprop="description" content="人帅也要多读书，多学习，多运动">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="费曼的门徒">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">java多线程之FutureTask

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-07-01 21:14:54 / 修改时间：22:51:51" itemprop="dateCreated datePublished" datetime="2019-07-01T21:14:54+08:00">2019-07-01</time>
            

            
              

              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/java多线程/" itemprop="url" rel="index"><span itemprop="name">java多线程</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="FutureTask和Future"><a href="#FutureTask和Future" class="headerlink" title="FutureTask和Future"></a>FutureTask和Future</h2><h3 id="Future"><a href="#Future" class="headerlink" title="Future"></a>Future</h3><h4 id="Future接口主要方法："><a href="#Future接口主要方法：" class="headerlink" title="Future接口主要方法："></a>Future接口主要方法：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">boolean cancel(boolean mayInterruptIfRunning);</span><br><span class="line"></span><br><span class="line">boolean isCancelled();</span><br><span class="line"></span><br><span class="line">boolean isDone();</span><br><span class="line"></span><br><span class="line">V get() throws InterruptedException, ExecutionException;</span><br><span class="line"></span><br><span class="line">V get(long timeout, TimeUnit unit)</span><br><span class="line">    throws InterruptedException, ExecutionException, TimeoutException;</span><br></pre></td></tr></table></figure>

<h3 id="FutureTask"><a href="#FutureTask" class="headerlink" title="FutureTask"></a>FutureTask</h3><p>FutureTask是Future的实现类，它提供了对Future的基本实现。可使用FutureTask包装Callable或Runnable对象，因为FutureTask实现了Runnable，所以也可以将FutureTask提交给Executor</p>
<h4 id="FutureTask的几种状态"><a href="#FutureTask的几种状态" class="headerlink" title="FutureTask的几种状态"></a>FutureTask的几种状态</h4><p>FutureTask实现了Runnable和Future接口。因此，FutureTask可以交给<br>Executor执行，也可以由调用线程直接执行（FutureTask.run()）。根据FutureTask.run()方法被执行<br>的时机，FutureTask可以处于下面3种状态。</p>
<ol>
<li>未启动:FutureTask.run()方法还没有被执行之前，FutureTask处于未启动状态。当创建一<br>个FutureTask，且没有执行FutureTask.run()方法之前，这个FutureTask处于未启动状态。</li>
<li>已启动:FutureTask.run()方法被执行的过程中，FutureTask处于已启动状态。</li>
<li>已完成:此状态有三种情况<ul>
<li>正常结束：FutureTask.run()方法执行完后。</li>
<li>被取消：FutureTask.cancel（…）</li>
<li>异常结束： 执行FutureTask.run()方法时抛出异常而异常结束，FutureTask处于已完成状态</li>
</ul>
</li>
</ol>
<h4 id="FutureTask中get和cancel"><a href="#FutureTask中get和cancel" class="headerlink" title="FutureTask中get和cancel"></a>FutureTask中get和cancel</h4><ol>
<li>get方法：<code>V get() throws InterruptedException, ExecutionException;</code><ul>
<li>当FutureTask处于未启动或已启动状态时，执行FutureTask.get()方法将导致调用线程阻塞；</li>
<li>当FutureTask处于已完成状态，调用FutureTask.get()方法将导致调用线程立即返回结果或者抛出异常。<ol start="2">
<li>cancel方法: <code>boolean cancel(boolean mayInterruptIfRunning);</code></li>
</ol>
</li>
<li>当FutureTask处于未启动状态时，执行FutureTask.cancel()方法将导致此任务永远不会被执行；</li>
<li>当FutureTask处于已启动状态时，执行FutureTask.cancel（true）方法将以中断执行此任务线程的方式来试图停止任务；</li>
<li>当FutureTask处于已启动状态时，执行FutureTask.cancel（false）方法将不会对正在执行此任务的线程产生影响（让正在执行的任务运行完成）；</li>
<li>当FutureTask处于已完成状态时，执行FutureTask.cancel（…）方法将返回false。</li>
</ul>
</li>
<li>get和cancel执行示例图<br><img src="/source/images/jus/FutureTask1.png" alt="FutureTask的get和cancel的执行示意图.jpg"></li>
</ol>
<h4 id="FutureTask和Future的使用"><a href="#FutureTask和Future的使用" class="headerlink" title="FutureTask和Future的使用"></a>FutureTask和Future的使用</h4><p>Callable、Future、FutureTask一般都是和线程池配合使用的,以下是常用方法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;T&gt; Future&lt;T&gt; submit(Callable&lt;T&gt; task);</span><br><span class="line">&lt;T&gt; Future&lt;T&gt; submit(Runnable task, T result);</span><br><span class="line">&lt;T&gt; List&lt;Future&lt;T&gt;&gt; invokeAll(Collection&lt;? extends Callable&lt;T&gt;&gt; tasks)throws InterruptedException;</span><br><span class="line">&lt;T&gt; List&lt;Future&lt;T&gt;&gt; invokeAll(Collection&lt;? extends Callable&lt;T&gt;&gt; tasks,long timeout, TimeUnit unit)throws  InterruptedException;</span><br></pre></td></tr></table></figure>

<ol>
<li><p>Callable+Future使用示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"> public class FutureTaskTest &#123;</span><br><span class="line">    static class CallableTask implements Callable&lt;String&gt; &#123;</span><br><span class="line">        private Integer sleepTime;</span><br><span class="line"></span><br><span class="line">        public CallableTask(Integer sleepTime) &#123;</span><br><span class="line">            this.sleepTime = sleepTime;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        @Override</span><br><span class="line">        public String call() throws Exception &#123;</span><br><span class="line">            System.out.println(Thread.currentThread().getName()+&quot;--begin--&quot;+System.currentTimeMillis());</span><br><span class="line">            Thread.sleep(sleepTime);</span><br><span class="line">            System.out.println(Thread.currentThread().getName()+&quot;-------end--&quot;+System.currentTimeMillis());</span><br><span class="line">            return Thread.currentThread().getName();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line"></span><br><span class="line">        ExecutorService executorService = Executors.newFixedThreadPool(3);</span><br><span class="line"></span><br><span class="line">        List&lt;Callable&lt;String&gt;&gt; callableList = new ArrayList&lt;&gt;();</span><br><span class="line">        callableList.add(new CallableTask(2000));</span><br><span class="line">        callableList.add(new CallableTask(5000));</span><br><span class="line">        callableList.add(new CallableTask(2000));</span><br><span class="line"></span><br><span class="line">        try &#123;</span><br><span class="line">            List&lt;Future&lt;String&gt;&gt; futures = executorService.invokeAll(callableList);</span><br><span class="line">            System.out.println(&quot;return future--&quot;+System.currentTimeMillis());</span><br><span class="line">            for (Future future : futures) &#123;</span><br><span class="line">                System.out.println(future.get() + &quot;--get---&quot;+System.currentTimeMillis());</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        System.out.println(&quot;main thread compelete&quot;);</span><br><span class="line">        executorService.shutdown();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">console result:</span><br><span class="line">pool-1-thread-1--begin--1561992318002</span><br><span class="line">pool-1-thread-3--begin--1561992318002</span><br><span class="line">pool-1-thread-2--begin--1561992318002</span><br><span class="line">pool-1-thread-3-------end--1561992320003</span><br><span class="line">pool-1-thread-1-------end--1561992320003</span><br><span class="line">pool-1-thread-2-------end--1561992323003</span><br><span class="line">return future--1561992323003</span><br><span class="line">pool-1-thread-1--get---1561992323003</span><br><span class="line">pool-1-thread-2--get---1561992323004</span><br><span class="line">pool-1-thread-3--get---1561992323004</span><br></pre></td></tr></table></figure>
</li>
<li><p>Callable+FutureTask使用示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">public static class CallableThread implements Callable&lt;String&gt;</span><br><span class="line">&#123;</span><br><span class="line">    public String call() throws Exception</span><br><span class="line">    &#123;</span><br><span class="line">        System.out.println(&quot;进入CallableThread的call()方法, 开始睡觉, 睡觉时间为&quot; + System.currentTimeMillis());</span><br><span class="line">        Thread.sleep(10000);</span><br><span class="line">        return &quot;123&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">    </span><br><span class="line">public static void main(String[] args) throws Exception</span><br><span class="line">&#123;</span><br><span class="line">    ExecutorService es = Executors.newCachedThreadPool();</span><br><span class="line">    CallableThread ct = new CallableThread();</span><br><span class="line">    FutureTask&lt;String&gt; f = new FutureTask&lt;String&gt;(ct);</span><br><span class="line">    es.submit(f);</span><br><span class="line">    es.shutdown();</span><br><span class="line">        </span><br><span class="line">    Thread.sleep(5000);</span><br><span class="line">    System.out.println(&quot;主线程等待5秒, 当前时间为&quot; + System.currentTimeMillis());</span><br><span class="line">        </span><br><span class="line">    String str = f.get();</span><br><span class="line">    System.out.println(&quot;Future已拿到数据, str = &quot; + str + &quot;, 当前时间为&quot; + System.currentTimeMillis());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Callable+Future的方式，es.submit(ct)方法返回的Future，底层实现new出来的是一个FutureTask</p>
</li>
</ol>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/06/26/java多线程之synchronized-volatle和final关键字/" rel="next" title="java多线程之synchronized,volatle和final关键字">
                <i class="fa fa-chevron-left"></i> java多线程之synchronized,volatle和final关键字
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/07/09/JSON使用经验之java对象与json字符串的互转问题/" rel="prev" title="JSON使用经验之java对象与json字符串的互转问题">
                JSON使用经验之java对象与json字符串的互转问题 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Thomas Wu">
            
              <p class="site-author-name" itemprop="name">Thomas Wu</p>
              <div class="site-description motion-element" itemprop="description">人帅也要多读书，多学习，多运动</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">24</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">9</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">6</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/peach-boy" title="GitHub &rarr; https://github.com/peach-boy" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="/1414924381@qq.com" title="E-Mail &rarr; 1414924381@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            </div>
          

          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/xrq730/" title="https://www.cnblogs.com/xrq730/" rel="noopener" target="_blank">五月的仓颉</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.w3cschool.cn/architectroad/" title="https://www.w3cschool.cn/architectroad/" rel="noopener" target="_blank">沈剑架构师之路</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://crossoverjie.top/" title="https://crossoverjie.top/" rel="noopener" target="_blank">crossoverjie</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.jianshu.com/u/2766e4cfc391" title="https://www.jianshu.com/u/2766e4cfc391" rel="noopener" target="_blank">高广超</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#FutureTask和Future"><span class="nav-number">1.</span> <span class="nav-text">FutureTask和Future</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Future"><span class="nav-number">1.1.</span> <span class="nav-text">Future</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Future接口主要方法："><span class="nav-number">1.1.1.</span> <span class="nav-text">Future接口主要方法：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#FutureTask"><span class="nav-number">1.2.</span> <span class="nav-text">FutureTask</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#FutureTask的几种状态"><span class="nav-number">1.2.1.</span> <span class="nav-text">FutureTask的几种状态</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#FutureTask中get和cancel"><span class="nav-number">1.2.2.</span> <span class="nav-text">FutureTask中get和cancel</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#FutureTask和Future的使用"><span class="nav-number">1.2.3.</span> <span class="nav-text">FutureTask和Future的使用</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Thomas Wu</span>

  

  
</div>









        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/affix.js?v=7.1.2"></script>

  <script src="/js/schemes/pisces.js?v=7.1.2"></script>




  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  

  

  


  


  




  

  

  

  

  

  

  

  

  

  

  

  

  

  

</body>
</html>
